home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / kms20src.lha / KMSC / msgbase3.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  47KB  |  1,549 lines

  1. /**********************************
  2.  *              KMS               *
  3.  **********************************
  4.  *  ©1993 by BlackMagic Software  *
  5.  **********************************
  6.  *                                *
  7.  **********************************/
  8.  
  9. #include <KMS/KMS.h>
  10.  
  11. Prototype UBYTE ReadMsg(UMSMsgNum, ULONG);
  12. Prototype BOOL WriteMsg(UWORD, struct AreaNode *, STRPTR, STRPTR);
  13.  
  14. LONG DeleteFile(STRPTR);
  15.  
  16. /*****************************
  17.  * Externe Globale Variablen *
  18.  *****************************/
  19.  
  20. extern struct KMSBase *KMSBase;
  21. extern struct LocalConfig *KMS_LC;
  22.  
  23. extern UMSAccount MyUMSAccount;
  24. extern UMSAccount SysUMSAccount;
  25.  
  26. extern TEXT PathString[];
  27.  
  28. extern STRPTR PPArg;
  29. extern STRPTR PPArg2;
  30. extern STRPTR PPArg3;
  31. extern STRPTR PPArg4;
  32.  
  33. extern STRPTR KMSVers;
  34.  
  35. extern UBYTE ShutDown, Plop;
  36.  
  37. extern TEXT KMSTempDat[];
  38.  
  39. extern TEXT BinaryName[];
  40. extern TEXT BinaryPath[];
  41. extern ULONG BinarySize;
  42.  
  43. extern UWORD AutoAct;
  44.  
  45. extern BOOL Spying;
  46.  
  47. /*********************
  48.  * Globale Variablen *
  49.  *********************/
  50.  
  51. UMSMsgNum Lastmsg = 0;
  52.  
  53. STRPTR RMsgText = NULL;
  54. STRPTR RFromName = NULL;
  55. STRPTR RFromAddr = NULL;
  56. STRPTR RToName = NULL;
  57. STRPTR RToAddr = NULL;
  58. STRPTR RReplyGroup = NULL;
  59. STRPTR RReplyName = NULL;
  60. STRPTR RReplyAddr = NULL;
  61. STRPTR RMsgID = NULL;
  62. STRPTR RCreationDate = NULL;
  63. STRPTR RReceiveDate = NULL;
  64. STRPTR RReferID = NULL;
  65. STRPTR RGroup = NULL;
  66. STRPTR RSubject = NULL;
  67. STRPTR RAttributes = NULL;
  68. STRPTR RComments = NULL;
  69. STRPTR ROrganization = NULL;
  70. STRPTR RDistribution = NULL;
  71. STRPTR RNewsReader = NULL;
  72.  
  73. struct MessageInfo RMsgInfo;
  74.  
  75. struct TagItem UMSReadTags[23] =
  76.    {
  77.    {UMSTAG_RMsgNum,0},
  78.    {UMSTAG_RMsgText,&RMsgText},
  79.    {UMSTAG_RFromName,&RFromName},
  80.    {UMSTAG_RFromAddr,&RFromAddr},
  81.    {UMSTAG_RToName,&RToName},
  82.    {UMSTAG_RToAddr,&RToAddr},
  83.    {UMSTAG_RMsgID,&RMsgID},
  84.    {UMSTAG_RCreationDate,&RCreationDate},
  85.    {UMSTAG_RReceiveDate,&RReceiveDate},
  86.    {UMSTAG_RReferID,&RReferID},
  87.    {UMSTAG_RGroup,&RGroup},
  88.    {UMSTAG_RSubject,&RSubject},
  89.    {UMSTAG_RAttributes,&RAttributes},
  90.    {UMSTAG_RComments,&RComments},
  91.    {UMSTAG_ROrganization,&ROrganization},
  92.    {UMSTAG_RDistribution,&RDistribution},
  93.    {UMSTAG_RReplyGroup,&RReplyGroup},
  94.    {UMSTAG_RReplyName,&RReplyName},
  95.    {UMSTAG_RReplyAddr,&RReplyAddr},
  96.    {UMSTAG_RNewsreader,&RNewsReader},
  97.    {UMSTAG_RMsgInfo,&RMsgInfo},
  98.    {TAG_DONE,0}
  99.    };
  100.  
  101. /***************************************
  102.  * Nachricht lesen                     *
  103.  ***************************************
  104.  * I: Msg-Nummer, Flags                *
  105.  * O: CTRL-C/X oder 0                  *
  106.  ***************************************/
  107.  
  108. /// "ReadMsg"
  109.  
  110. UBYTE ReadMsg(UMSMsgNum msgnum, ULONG flags)
  111.    {
  112.    UBYTE abbruch = 0;
  113.    BOOL fileattach = FALSE;
  114.    TEXT fname[LEN_DOSFILE+1];
  115.    TEXT fsizebuff[LEN_NUMBER+1];
  116.    ULONG fsize;
  117.    BOOL spymerk = FALSE;
  118.    static BOOL nnmsg = TRUE;
  119.    static BOOL nnarea = FALSE;
  120.    static BOOL nsarea = FALSE;
  121.  
  122.    static UMSMsgNum merkmsg = 0;
  123.  
  124.    if (flags == RF_RESET)
  125.       {
  126.       Lastmsg = 0;
  127.       nnmsg = TRUE;
  128.       nnarea = FALSE;
  129.       nsarea = FALSE;
  130.       KMS_LC->Session.CurrentUser->UserData.Flags &= ~UF_RMODE_RANGE;
  131.       return 0;
  132.       }
  133.  
  134.    SelectArea(KMS_LC->Session.CurrentArea->AreaData.MBName);
  135.  
  136.    if (!msgnum)
  137.       {
  138.       if (flags & RF_SAME && !(msgnum = Lastmsg))
  139.          SysMsg(NO_MSG_READ);
  140.       else if (flags & RF_NEW && !(msgnum = NextMsg(0, MLIST_NEW)))
  141.          {
  142.          if (!nnarea)
  143.             {
  144.             SysMsg(NO_NEXTNEW_MSG);
  145.             nnarea = TRUE;
  146.             }
  147.          else
  148.             {
  149.             ReadMsg(0,RF_RESET);
  150.             ListAreas(NULL,ALIST_WHOLE|ALIST_NEXTNEW);
  151.             }
  152.          }
  153.       else if (flags & RF_SEL && !(msgnum = NextMsg(Lastmsg, MLIST_SEL)))
  154.          {
  155.          if (!nsarea)
  156.             {
  157.             SysMsg(NO_NEXTSEL_MSG);
  158.             nsarea = TRUE;
  159.             }
  160.          else
  161.             {
  162.             ReadMsg(0,RF_RESET);
  163.             ListAreas(NULL,ALIST_WHOLE|ALIST_NEXTSEL);
  164.             }
  165.          }
  166.       else if (flags & RF_RANGE && !(msgnum = NextMsg(Lastmsg, MLIST_RRANGE)))
  167.          {
  168.          SysMsg(NO_NEXTRANGE_MSG);
  169.          KMS_LC->Session.CurrentUser->UserData.Flags &= ~UF_RMODE_RANGE;
  170.          }
  171.       else if (flags & RF_NEXT && !(msgnum = NextMsg(Lastmsg, MLIST_ALL)))
  172.          SysMsg(NO_NEXT_MSG);
  173.       else if (flags & RF_PREV && !(msgnum = PrevMsg(Lastmsg, MLIST_ALL)))
  174.          SysMsg(NO_PREV_MSG);
  175.       else if (flags & RF_NXTSEL && !(msgnum = NextMsg(Lastmsg, MLIST_SEL)))
  176.          SysMsg(NO_NEXTSEL_MSG);
  177.       else if (flags & RF_PRVSEL && !(msgnum = PrevMsg(Lastmsg, MLIST_SEL)))
  178.          SysMsg(NO_PREVSEL_MSG);
  179.       else if (flags & RF_FIRST && !(msgnum = NextMsg(0, MLIST_ALL)))
  180.          SysMsg(NO_MSG_FOUND);
  181.       else if (flags & RF_LAST && !(msgnum = PrevMsg(0, MLIST_ALL)))
  182.          SysMsg(NO_MSG_FOUND);
  183.       else if (flags & RF_NREPLY && !(msgnum = NextReply(Lastmsg)))
  184.          {
  185.          if (!nnmsg && !(flags & RF_NORMSG))
  186.             {
  187.             SysMsg(NO_NEXT_REPLY);
  188.             nnmsg = TRUE;
  189.             }
  190.          else
  191.             {
  192.             if (!(msgnum = NextMsg(0, MLIST_NEW)))
  193.                {
  194.                if (!nnarea)
  195.                   {
  196.                   SysMsg(NO_NEXTNEW_MSG);
  197.                   nnarea = TRUE;
  198.                   }
  199.                else
  200.                   {
  201.                   ReadMsg(0,RF_RESET);
  202.                   ListAreas(NULL,ALIST_WHOLE|ALIST_NEXTNEW);
  203.                   }
  204.                }
  205.             }
  206.          }
  207.       else if (flags & RF_PREPLY && !(msgnum = PrevReply(Lastmsg)))
  208.          SysMsg(NO_PREV_REPLY);
  209.       else if (flags & RF_RIGHT && !(msgnum = ChainRight(MyUMSAccount, Lastmsg)))
  210.          SysMsg(NO_RIGHT_REPLY);
  211.       else if (flags & RF_LEFT && !(msgnum = ChainLeft(MyUMSAccount, Lastmsg)))
  212.          SysMsg(NO_LEFT_REPLY);
  213.       else if (flags & RF_PARENT && !(msgnum = ChainUp(MyUMSAccount, Lastmsg)))
  214.          SysMsg(NO_PARENT_REPLY);
  215.       else if (flags & RF_CONT && !(msgnum = merkmsg))
  216.          SysMsg(NO_MARKED_MSG);
  217.       else if (flags & RF_ROOT)
  218.          {
  219.          if (msgnum = ChainUp(MyUMSAccount, Lastmsg))
  220.             {
  221.             UMSMsgNum msg;
  222.             while(msg = ChainUp(MyUMSAccount, msgnum))
  223.                msgnum = msg;
  224.             }
  225.          else
  226.             SysMsg(NO_PARENT_REPLY);
  227.          }
  228.       else if (flags & RF_DOWN)
  229.          {
  230.          UMSMsgNum msg;
  231.          if (msgnum = ChainDown(MyUMSAccount, Lastmsg))
  232.             while(msg = ChainLeft(MyUMSAccount, msgnum))
  233.                msgnum = msg;
  234.          if (!msgnum)
  235.             SysMsg(NO_DOWN_REPLY);
  236.          }
  237.       }
  238.  
  239.    if (!msgnum)
  240.       return 0;
  241.  
  242.    UMSReadTags[0].ti_Data = msgnum;
  243.  
  244.    /* Msg nie dagewesen oder gelöscht? */
  245.  
  246.    if (!ReadUMSMsg(MyUMSAccount, &UMSReadTags[0])
  247.       || !(RMsgInfo.msgi_LoginStatus & KMSLSTATF_Visible))
  248.       {
  249.       SysMsg(MSG_NOT_FOUND);
  250.       FreeUMSMsg(MyUMSAccount, msgnum);
  251.       return 0;
  252.       }
  253.  
  254.    /* Msg nicht in aktueller Gruppe? */
  255.  
  256.    if (!(RMsgInfo.msgi_LoginStatus & KMSLSTATF_InGroup))
  257.       {
  258.       STRPTR rgroup = "";
  259.       if (RGroup)
  260.          rgroup = RGroup;
  261.       struct AreaNode *anode = AreaSearch(rgroup);
  262.       if (anode)
  263.          {
  264.          UBYTE curraccess = CheckAccess(anode);
  265.          if (curraccess & AACC_READ)
  266.             {
  267.             CreatePath(anode);
  268.             PPArg = PathString;
  269.             SysMsg(CROSS_REF);
  270.             if (YNRequest(CHANGE_GROUP, TRUE))
  271.                {
  272.                PPArg = NULL;
  273.                KMS_LC->Session.CurrentArea = anode;
  274.                KMS_LC->Session.CurrentAccess = curraccess;
  275.                SelectArea(anode->AreaData.MBName);
  276.                }
  277.             else
  278.                {
  279.                PPArg = NULL;
  280.                FreeUMSMsg(MyUMSAccount, msgnum);
  281.                return 0;
  282.                }
  283.             }
  284.          else
  285.             {
  286.             FreeUMSMsg(MyUMSAccount, msgnum);
  287.             PPArg = KMS_LC->Session.InputBuffer;
  288.             SysMsg(NO_READ_ACCESS);
  289.             PPArg = NULL;
  290.             return 0;
  291.             }
  292.          }
  293.       else
  294.          {
  295.          PPArg = rgroup;
  296.          SysMsg(INV_CROSS_REF);
  297.          PPArg = NULL;
  298.  
  299.          FreeUMSMsg(MyUMSAccount, msgnum);
  300.  
  301.          return 0;
  302.          }
  303.       }
  304.  
  305.    /* Alles ok */
  306.  
  307.    merkmsg = Lastmsg;
  308.    Lastmsg = msgnum;
  309.    nnmsg = FALSE;
  310.    nnarea = FALSE;
  311.  
  312.    /* Header-Info aufbereiten */
  313.  
  314.    TEXT up[2] = " ", down[2] = " ", left[2] = " ", right[2] = " ", local[2] = "*";
  315.    TEXT numbuff[5+1], lenbuff[5+1], subbuff[LEN_MAXLINE+1];
  316.  
  317.    if (RMsgInfo.msgi_ChainUp)
  318.       up[0] = '^';
  319.    if (RMsgInfo.msgi_ChainDn)
  320.       down[0] = 'v';
  321.    if (RMsgInfo.msgi_ChainLt)
  322.       left[0] = '<';
  323.    if (RMsgInfo.msgi_ChainRt)
  324.       right[0] = '>';
  325.    if (RMsgInfo.msgi_GlobalStatus & UMSGSTATF_Exported)
  326.       local[0] = ' ';
  327.  
  328.    STRPTR rfromname = "";
  329.    STRPTR rcreationdate = "";
  330.    STRPTR rtoname = "";
  331.    STRPTR rmsgtext = "\n";
  332.    STRPTR rsubject = "";
  333.    if (RFromName) rfromname = RFromName;
  334.    if (RCreationDate) rcreationdate = RCreationDate;
  335.    if (RToName) rtoname = RToName;
  336.    if (RMsgText) rmsgtext = RMsgText;
  337.    if (RSubject) rsubject = RSubject;
  338.  
  339.    sprintf(numbuff, "%05ld", msgnum);
  340.    sprintf(lenbuff, "%5ld", strlen(rmsgtext));
  341.    strncpy(subbuff, rsubject, KMS_LC->Session.CurrentUser->UserData.LineLen - 20);
  342.    subbuff[KMS_LC->Session.CurrentUser->UserData.LineLen - 20] = '\0';
  343.  
  344.    /* Spionieren unterbinden */
  345.  
  346.    spymerk = Spying;
  347.    Spying = FALSE;
  348.  
  349.    /* Nachrichten-Header-Info ausgeben */
  350.  
  351.    KMS_LC->Session.LineCounter = 1;
  352.  
  353.    PPArg = up; PPArg2 = rcreationdate;
  354.    ParsePrint(KMSBase->MsgHead[0], 0);
  355.  
  356.    PPArg = left; PPArg2 = numbuff; PPArg3 = right; PPArg4 = rfromname;
  357.    ParsePrint(KMSBase->MsgHead[1], 0);
  358.  
  359.    PPArg = down; PPArg2 = rtoname; PPArg3 = NULL; PPArg4 = NULL;
  360.    ParsePrint(KMSBase->MsgHead[2], 0);
  361.  
  362.    PPArg = local; PPArg2 = lenbuff; PPArg3 = local; PPArg4 = subbuff;
  363.    ParsePrint(KMSBase->MsgHead[3], 0);
  364.  
  365.    PPArg = NULL; PPArg2 = NULL; PPArg3 = NULL; PPArg4 = NULL;
  366.  
  367.    TEXT umsflags[23];
  368.  
  369.    if ((flags & RF_VERBOSE) || (KMS_LC->Session.CurrentUser->UserData.Flags & UF_HEAD_LONG))
  370.       {
  371.       UMSSet stat = RMsgInfo.msgi_UserStatus;
  372.  
  373.       strcpy(umsflags, "U: --------- G: ------");
  374.  
  375.       if (stat & UMSUSTATF_Archive)
  376.          umsflags[3] = 'A';
  377.       if (stat & UMSUSTATF_Junk)
  378.          umsflags[4] = 'J';
  379.       if (stat & UMSUSTATF_PostPoned)
  380.          umsflags[5] = 'P';
  381.       if (stat & UMSUSTATF_Selected)
  382.          umsflags[6] = 'S';
  383.       if (stat & UMSUSTATF_Old)
  384.          umsflags[7] = 'O';
  385.       if (stat & UMSUSTATF_WriteAccess)
  386.          umsflags[8] = 'W';
  387.       if (stat & UMSUSTATF_ReadAccess)
  388.          umsflags[9] = 'R';
  389.       if (stat & UMSUSTATF_ViewAccess)
  390.          umsflags[10] = 'V';
  391.       if (stat & UMSUSTATF_Owner)
  392.          umsflags[11] = 'O';
  393.  
  394.       stat = RMsgInfo.msgi_GlobalStatus;
  395.  
  396.       if (stat & UMSGSTATF_Deleted)
  397.          umsflags[16] = 'D';
  398.       if (stat & UMSGSTATF_Expired)
  399.          umsflags[17] = 'X';
  400.       if (stat & UMSGSTATF_Exported)
  401.          umsflags[18] = 'E';
  402.       if (stat & UMSGSTATF_Orphan)
  403.          umsflags[19] = 'O';
  404.       if (stat & UMSGSTATF_Link)
  405.          umsflags[20] = 'L';
  406.       if (stat & UMSGSTATF_HardLink)
  407.          umsflags[21] = 'H';
  408.       }
  409.  
  410.    if (KMS_LC->Session.CurrentUser->UserData.Flags & UF_EMU_ANSI)
  411.       Print(OFF, PF_NOLF|PF_NOBRK);
  412.  
  413.    KMS_LC->Session.LineCounter = 5;
  414.  
  415.    if (!strcmp(KMS_LC->Session.CurrentArea->AreaData.MBName, "*KMS-GLOBAL*"))
  416.       {
  417.       if (RGroup)
  418.          MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[14], 0), MsgPrint(RGroup, 0);
  419.       else
  420.          MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[14], 0), MsgPrint("-UMS-MAIL-", 0);
  421.       }
  422.    if (RMsgID)
  423.       MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[0], 0), MsgPrint(RMsgID, 0);
  424.    if (RReferID)
  425.       MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[1], 0), MsgPrint(RReferID, 0);
  426.    if (RFromAddr)
  427.       MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[2], 0), MsgPrint(RFromAddr, 0);
  428.    if (RToAddr)
  429.       MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[3], 0), MsgPrint(RToAddr, 0);
  430.    if (RReplyName)
  431.       MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[11], 0), MsgPrint(RReplyName, 0);
  432.    if (RReplyAddr)
  433.       MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[12], 0), MsgPrint(RReplyAddr, 0);
  434.    if (RReplyGroup)
  435.       MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[13], 0), MsgPrint(RReplyGroup, 0);
  436.    if (ROrganization)
  437.       MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[4], 0), MsgPrint(ROrganization, 0);
  438.  
  439.    if ((flags & RF_VERBOSE) || (KMS_LC->Session.CurrentUser->UserData.Flags & UF_HEAD_LONG))
  440.       {
  441.       if (umsflags)
  442.          MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[5], 0), MsgPrint(umsflags, 0);
  443.       if (RNewsReader)
  444.          MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[6], 0), MsgPrint(RNewsReader, 0);
  445.       if (RAttributes)
  446.          MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[7], 0), MsgPrint(RAttributes, 0);
  447.       if (RDistribution)
  448.          MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[8], 0), MsgPrint(RDistribution, 0);
  449.       if (RComments)
  450.          MsgPrint("\n", 0), MsgParsePrint(KMSBase->MsgInfos[9], 0), MsgPrint(RComments, 0);
  451.       }
  452.  
  453.    if (KMS_LC->Session.CurrentUser->UserData.Flags & UF_EMU_ANSI)
  454.       Print(OFF, PF_NOLF|PF_NOBRK);
  455.  
  456.    /* Auf File-Attach prüfen */
  457.  
  458.    STRPTR arg;
  459.  
  460.    if (RAttributes)
  461.       {
  462.       if (arg = strstr(RAttributes, "KMS_FNAME:"))
  463.          {
  464.          fsize = 0;
  465.          *fname = '\0';
  466.          *fsizebuff = '\0';
  467.  
  468.          /* Fileinfo besorgen */
  469.  
  470.          /* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
  471.  
  472.          sscanf(arg, "KMS_FNAME:%30s", fname);
  473.  
  474.          if (arg = strstr(RAttributes, "KMS_FSIZE:"))
  475.             sscanf(arg, "KMS_FSIZE:%d", &fsize);
  476.  
  477.          sprintf(fsizebuff, "%ld", fsize);
  478.  
  479.          MsgPrint("\n\n", 0);
  480.  
  481.          if (KMS_LC->Session.CurrentArea->AreaData.Type & ATYPE_FILES)
  482.             {
  483.             MsgParsePrint(KMSBase->MsgInfos[10], 0);
  484.             MsgPrint(fname, 0);
  485.             MsgPrint(" (", 0);
  486.             MsgPrint(fsizebuff, 0);
  487.             MsgPrint(" Bytes)", 0);
  488.             }
  489.          else
  490.             {
  491.             MsgParsePrint(KMSBase->MsgInfos[10], 0);
  492.             MsgPrint(fname, 0);
  493.             MsgPrint(" (", 0);
  494.             MsgPrint(fsizebuff, 0);
  495.             MsgPrint(" Bytes)", 0);
  496.             }
  497.  
  498.          if (KMS_LC->Session.CurrentUser->UserData.Flags & UF_EMU_ANSI)
  499.             Print(OFF, PF_NOLF|PF_NOBRK);
  500.  
  501.          fileattach = TRUE;
  502.          }
  503.       }
  504.  
  505.    /* Nachrichten-Text ausgeben */
  506.  
  507.    MsgPrint("\n\n", 0);
  508.  
  509.    if (flags & RF_ROT13)
  510.       Rot13(rmsgtext);
  511.  
  512.    WordWrap(rmsgtext, KMS_LC->Session.CurrentUser->UserData.LineLen, 0);
  513.  
  514.    abbruch = MsgPrint(rmsgtext, MP_ATTRIB);
  515.  
  516.    if (!abbruch)
  517.       if (rmsgtext[strlen(rmsgtext)-1] != '\n')
  518.          abbruch = MsgPrint("\n", 0);
  519.  
  520.    /* Spionieren wieder erlaubt */
  521.  
  522.    Spying = spymerk;
  523.  
  524.    /* Nachricht als gelesen markieren -> Local 1 löschen */
  525.  
  526.    UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg,        msgnum,
  527.                                UMSTAG_SelWriteLocal, TRUE,
  528.                                UMSTAG_SelUnset,      KMSLSTATF_Unread,
  529.                                TAG_DONE);
  530.  
  531.    FreeUMSMsg(MyUMSAccount,msgnum);
  532.  
  533.    if (abbruch == 1)
  534.       {
  535.       /* CRS LEFT */
  536.  
  537.       AutoAct = ACTION_CRS_LEFT;
  538.  
  539.       return 0;
  540.       }
  541.    else if (abbruch == 2)
  542.       {
  543.       /* CRS RIGHT */
  544.  
  545.       AutoAct = ACTION_CRS_RIGHT;
  546.  
  547.       return 0;
  548.       }
  549.    else if (abbruch == 3)
  550.       {
  551.       /* SHIFT CURSOR LEFT */
  552.  
  553.       AutoAct = ACTION_LIST_CURRENT;
  554.  
  555.       return 0;
  556.       }
  557.    else if (abbruch == 4)
  558.       {
  559.       /* SHIFT CURSOR RIGHT = Naechstes Brett mit neuen Msgs */
  560.  
  561.       AutoAct = ACTION_SHIFT_CRS_RIGHT;
  562.  
  563.       return 0;
  564.       }
  565.    else if (abbruch == 5)
  566.       {
  567.       /* SHIFT CURSOR UP = Zuletzt gelesene nochmal */
  568.  
  569.       AutoAct = ACTION_SHIFT_CRS_UP;
  570.  
  571.       return 0;
  572.       }
  573.    else if (abbruch == 6)
  574.       {
  575.       /* SHIFT CURSOR DOWN = Kommentar auf zuletzt gelesene */
  576.  
  577.       AutoAct = ACTION_SHIFT_CRS_DOWN;
  578.  
  579.       return 0;
  580.       }
  581.    else if (abbruch == 7)
  582.       {
  583.       /* CURSOR UP */
  584.  
  585.       AutoAct = ACTION_LIST_CURRENT;
  586.  
  587.       return 0;
  588.       }
  589.  
  590.    if (fileattach)
  591.       {
  592.       if (!(KMS_LC->Session.CurrentArea->AreaData.Type & ATYPE_FILES))
  593.          {
  594.          PPArg = fname;
  595.          PPArg2 = fsizebuff;
  596.          SysMsg(FILEATTACH_MESSAGE);
  597.          PPArg = NULL;
  598.          PPArg2 = NULL;
  599.          }
  600.       }
  601.  
  602.    return abbruch;
  603.    }
  604.  
  605. ///
  606.  
  607. /***************************************
  608.  * Nachricht schreiben                 *
  609.  ***************************************
  610.  * I: Flags, Area, Datei, Empfänger    *
  611.  * O: Erfolg TRUE/FALSE                *
  612.  ***************************************/
  613.  
  614. /// "WriteMsg"
  615.  
  616. BOOL WriteMsg(UWORD flags, struct AreaNode *target, STRPTR infile, STRPTR toname)
  617.    {
  618.    TEXT buff[LEN_REALNAME+LEN_ADDRESS+1];
  619.    TEXT outbuff[LEN_PARSEOUT+1];
  620.    TEXT wcreationdate[20];
  621.    struct AreaNode *current = KMS_LC->Session.CurrentArea;
  622.    LONG error = 0;
  623.    STRPTR myorg;
  624.    STRPTR wmsgtext = "";
  625.    STRPTR wfromname = NULL;
  626.    STRPTR wtoname = NULL;
  627.    STRPTR wtoaddr = NULL;
  628.    STRPTR wreplyname = NULL;
  629.    STRPTR wreplyaddr = NULL;
  630.    STRPTR wreplygroup = NULL;
  631.    STRPTR wattributes = NULL;
  632.    STRPTR wsubject = "";
  633.    STRPTR wgroup = "";
  634.  
  635.    if (target)
  636.       current = target;
  637.    else if (flags & WF_PRIV)
  638.       {
  639.       TakeASem(FALSE);
  640.       current = SetArea(1);
  641.       DropASem();
  642.       }
  643.  
  644.    if (!(CheckAccess(current) & AACC_WRITE))
  645.       {
  646.       PPArg = KMS_LC->Session.InputBuffer;
  647.       SysMsg(NO_WRITE_ACCESS);
  648.       PPArg = NULL;
  649.       return FALSE;
  650.       }
  651.  
  652.    if (flags & (WF_REPLY|WF_RESEND|WF_EDIT|WF_FORWARD))
  653.       {
  654.       if (!Lastmsg)
  655.          {
  656.          SysMsg(NO_MSG_READ);
  657.          return FALSE;
  658.          }
  659.  
  660.       UMSReadTags[0].ti_Data = Lastmsg;
  661.  
  662.       if (!ReadUMSMsg(MyUMSAccount,&UMSReadTags[0]))
  663.          {
  664.          SystemError("WriteMsg", "ReadUMSMsg");
  665.          FreeUMSMsg(MyUMSAccount, Lastmsg);
  666.          return FALSE;
  667.          }
  668.  
  669.       if (flags & (WF_RESEND|WF_EDIT))
  670.          {
  671.          if (!(RMsgInfo.msgi_UserStatus & UMSUSTATF_Owner))
  672.             {
  673.             SysMsg(MSG_NOT_OWNED);
  674.             FreeUMSMsg(MyUMSAccount, Lastmsg);
  675.             return FALSE;
  676.             }
  677.          }
  678.       }
  679.  
  680.    /* Msg-Header belegen */
  681.  
  682.    if (flags & (WF_NEW|WF_FORWARD))
  683.       {
  684.       if ((current->AreaData.Type & ATYPE_PRIVATE) || (current->AreaData.WriteFlag & AWF_TONAME))
  685.          {
  686.          /* ToName : Bei pers. Nachrichten oder oeffentl., wenn verlangt */
  687.  
  688.          if (toname)
  689.             {
  690.             strncpy(buff, toname, sizeof(buff)-1);
  691.             buff[sizeof(buff)-1] = '\0';
  692.             }
  693.          else
  694.             *buff = '\0';
  695.          GetAlias(buff, GA_NAME, LEN_REALNAME);
  696.  
  697.          if ((!strlen(buff) && (current->AreaData.Type & ATYPE_PRIVATE))
  698.             || (strlen(buff) && !(wtoname = strdup(buff)) && (current->AreaData.Type & ATYPE_PRIVATE)))
  699.             {
  700.             if (flags & WF_FORWARD)
  701.                FreeUMSMsg(MyUMSAccount, Lastmsg);
  702.  
  703.             GetAlias(NULL, GA_RESET, 0);
  704.  
  705.             return FALSE; /* Keine priv. Mail ohne Adressat */
  706.             }
  707.          }
  708.  
  709.       if (!(flags & WF_BINARY) && (current->AreaData.Type & ATYPE_PRIVATE))
  710.          {
  711.          /* ToAddr : Nur bei persoenlichen Nachrichten */
  712.          /* (Binaries nur lokal!) */
  713.  
  714.          *buff = '\0';
  715.          GetAlias(buff, GA_ADDRESS, LEN_ADDRESS);
  716.  
  717.          if (strlen(buff))
  718.             {
  719.             wtoaddr = strdup(buff);
  720.             if (!wtoaddr)
  721.                {
  722.                if (flags & WF_FORWARD)
  723.                   FreeUMSMsg(MyUMSAccount, Lastmsg);
  724.  
  725.                GetAlias(NULL, GA_RESET, 0);
  726.  
  727.                if (wtoname)
  728.                   free(wtoname);
  729.  
  730.                return FALSE;
  731.                }
  732.             }
  733.          }
  734.       }
  735.    else if (flags & WF_REPLY)
  736.       {
  737.       if (current->AreaData.Type & ATYPE_PRIVATE)
  738.          {
  739.          /* Evt. Reply-To berücksichtigen */
  740.  
  741.          if (RReplyName)
  742.             wtoname = strdup(RReplyName);
  743.          else if (RFromName)
  744.             wtoname = strdup(RFromName);
  745.  
  746.          if (RReplyAddr)
  747.             wtoaddr = strdup(RReplyAddr);
  748.          else if (RFromAddr)
  749.             wtoaddr = strdup(RFromAddr);
  750.  
  751.          if (RReplyName || RReplyAddr)
  752.             {
  753.             PPArg = RReplyName;
  754.             PPArg2 = RReplyAddr;
  755.             SysMsg(REPLY_TO);
  756.             PPArg = NULL;
  757.             PPArg2 = NULL;
  758.             }
  759.          }
  760.       else if (RFromName && (current->AreaData.WriteFlag & AWF_TONAME))
  761.          wtoname = strdup(RFromName);
  762.  
  763.       if (KMS_LC->Session.CurrentUser->UserData.Flags & UF_EXTSEND)
  764.          {
  765.          TEXT wtonamebuff[LEN_REALNAME+1];
  766.  
  767.          if (wtoname)
  768.             {
  769.             strncpy(wtonamebuff, wtoname, LEN_REALNAME);
  770.             wtonamebuff[LEN_REALNAME] = '\0';
  771.             free(wtoname);
  772.             wtoname = NULL;
  773.             }
  774.          else
  775.             *wtonamebuff = '\0';
  776.  
  777.          GetAlias(NULL, GA_RESET, 0);
  778.  
  779.          if ((current->AreaData.Type & ATYPE_PRIVATE) || (current->AreaData.WriteFlag & AWF_TONAME))
  780.             GetAlias(wtonamebuff, GA_NAME, LEN_REALNAME);
  781.  
  782.          if ((!strlen(wtonamebuff) && (current->AreaData.Type & ATYPE_PRIVATE))
  783.             || (strlen(wtonamebuff) && !(wtoname = strdup(wtonamebuff)) && (current->AreaData.Type & ATYPE_PRIVATE)))
  784.             {
  785.             if (flags & WF_FORWARD)
  786.                FreeUMSMsg(MyUMSAccount, Lastmsg);
  787.  
  788.             GetAlias(NULL, GA_RESET, 0);
  789.  
  790.             return FALSE;
  791.             }
  792.  
  793.          if (current->AreaData.Type & ATYPE_PRIVATE)
  794.             {
  795.             TEXT wtoaddrbuff[LEN_ADDRESS+1];
  796.  
  797.             if (wtoaddr)
  798.                {
  799.                strncpy(wtoaddrbuff, wtoaddr, LEN_ADDRESS);
  800.                wtoaddrbuff[LEN_ADDRESS] = '\0';
  801.                free(wtoaddr);
  802.                wtoaddr = NULL;
  803.                }
  804.             else
  805.                *wtoaddrbuff = '\0';
  806.  
  807.             GetAlias(wtoaddrbuff, GA_ADDRESS, LEN_ADDRESS);
  808.  
  809.             if (strlen(wtoaddrbuff) && !(wtoaddr = strdup(wtoaddrbuff)))
  810.                {
  811.                if (flags & WF_FORWARD)
  812.                   FreeUMSMsg(MyUMSAccount, Lastmsg);
  813.  
  814.                GetAlias(NULL, GA_RESET, 0);
  815.  
  816.                if (wtoname)
  817.                   free(wtoname);
  818.  
  819.                return FALSE;
  820.                }
  821.             }
  822.          }
  823.       }
  824.    else /* if (flags & (WF_RESEND|WF_EDIT)) */
  825.       {
  826.       if (RToName)
  827.          wtoname = strdup(RToName);
  828.       if (RToAddr)
  829.          wtoaddr = strdup(RToAddr);
  830.       }
  831.  
  832.    /* Alias-Puffer freigeben */
  833.  
  834.    GetAlias(NULL, GA_RESET, 0);
  835.  
  836.    /* Erstell-Datum */
  837.  
  838.    time_t zeit = time(NULL);
  839.    struct tm *tp = localtime(&zeit);
  840.    strftime(wcreationdate, 19, "%d %b %y %H:%M:%S", tp);
  841.  
  842.    /* Gruppenname */
  843.  
  844.    wgroup = current->AreaData.MBName;
  845.  
  846.    /* Evt. Followup-To berücksichtigen */
  847.  
  848.    if (RReplyGroup && (flags & WF_REPLY) && strlen(wgroup))
  849.       {
  850.       struct AreaNode *anode = AreaSearch(RReplyGroup);
  851.       if (anode)
  852.          {
  853.          UBYTE curraccess = CheckAccess(anode);
  854.          if (curraccess & AACC_WRITE)
  855.             {
  856.             CreatePath(anode);
  857.  
  858.             PPArg = PathString;
  859.             SysMsg(FOLLOWUP_TO);
  860.             PPArg = NULL;
  861.  
  862.             wgroup = RReplyGroup;
  863.             }
  864.          }
  865.       }
  866.  
  867.    /* Subject */
  868.  
  869.    if (!(flags & (WF_RESEND|WF_EDIT)))
  870.       {
  871.       TEXT rsubject[LEN_CMDINPUT+1];
  872.  
  873.       if (!(flags & WF_NEW))
  874.          {
  875.          if (RSubject)
  876.             {
  877.             if (!(flags & WF_FORWARD) && strncmp(RSubject, "Re:", 3) && strncmp(RSubject, "RE:", 3)
  878.                                      && strncmp(RSubject, "re:", 3)
  879.                && !(current->AreaData.WriteFlag & AWF_NORE))
  880.                strcpy(rsubject, "Re: ");
  881.             else
  882.                *rsubject = '\0';
  883.             strncat(rsubject, RSubject, LEN_CMDINPUT-strlen(rsubject));
  884.             rsubject[LEN_CMDINPUT] = '\0';
  885.             }
  886.          else
  887.             *rsubject = '\0';
  888.  
  889.          if ((flags & WF_REPLY) && target)
  890.             {
  891.             strncat(rsubject, " [", LEN_CMDINPUT-strlen(rsubject));
  892.             strncat(rsubject, KMS_LC->Session.CurrentArea->AreaData.MBName, LEN_CMDINPUT-strlen(rsubject));
  893.             strncat(rsubject, "]", LEN_CMDINPUT-strlen(rsubject));
  894.             rsubject[LEN_CMDINPUT] = '\0';
  895.             }
  896.          }
  897.  
  898.       if (flags & WF_NEW)
  899.          {
  900.          if (flags & WF_BINARY)
  901.             CmdInput(NULL, PROMPT_BINSHORT, NULL, NULL, LEN_SUBJECT, INF_PROMPT);
  902.          else
  903.             CmdInput(NULL, PROMPT_SUBJ, NULL, NULL, LEN_SUBJECT, INF_PROMPT);
  904.          }
  905.       else
  906.          CmdInput(NULL, PROMPT_SUBJ, NULL, rsubject, LEN_SUBJECT, INF_PROMPT|INF_DEFBUF);
  907.  
  908.       if (Plop || ShutDown || !strlen(KMS_LC->Session.InputBuffer))
  909.          {
  910.          if (flags & (WF_REPLY|WF_FORWARD))
  911.             FreeUMSMsg(MyUMSAccount, Lastmsg);
  912.          if (flags & (WF_NEW|WF_FORWARD))
  913.             {
  914.             if (wtoname)
  915.                free(wtoname);
  916.             if (wtoaddr)
  917.                free(wtoaddr);
  918.             }
  919.  
  920.          return FALSE;
  921.          }
  922.  
  923.       wsubject = (STRPTR)malloc((size_t)(strlen(KMS_LC->Session.InputBuffer)+1));
  924.       if (wsubject)
  925.          strcpy(wsubject, KMS_LC->Session.InputBuffer);
  926.       }
  927.    else /* if (flags & (WF_RESEND|WF_EDIT)) */
  928.       wsubject = RSubject;
  929.  
  930.    /* Nachrichten-Text erfassen */
  931.  
  932.    if (!(flags & WF_BINARY) || YNRequest(QUERY_BINLONG, TRUE))
  933.       {
  934.       STRPTR rmsgtext = "\n";
  935.       if (RMsgText)
  936.          rmsgtext = RMsgText;
  937.       if (flags & WF_REPLY)
  938.          {
  939.          CreateComment(rmsgtext, flags);
  940.          AddSignature();
  941.          }
  942.       else if (flags & WF_RESEND)
  943.          CreateResendForward(rmsgtext, WF_RESEND);
  944.       else if (flags & WF_EDIT)
  945.          CreateResendForward(rmsgtext, WF_EDIT);
  946.       else if (flags & WF_FORWARD)
  947.          CreateResendForward(rmsgtext, WF_FORWARD);
  948.       else if (infile)
  949.          CreatePrivImport(infile);
  950.       else
  951.          {
  952.          DeleteFile(KMSTempDat);
  953.          AddSignature();
  954.          }
  955.  
  956.       STRPTR editor;
  957.       TEXT cfgstring[20];
  958.  
  959.       if (KMS_LC->Device & DEV_CONSOLE)
  960.          strcpy(cfgstring, "KMS.coneditor");
  961.       else
  962.          strcpy(cfgstring, "KMS.remoteeditor");
  963.  
  964.       if ((KMS_LC->Session.CurrentUser->UserData.Flags & UF_SCREEN_ED) && (editor = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE)))
  965.          {
  966.          CreatePath(current);
  967.  
  968.          PPArg = KMSTempDat;
  969.          PPArg2 = PathString;
  970.          StdStringParse(editor, outbuff, LEN_PARSEOUT);
  971.          PPArg = NULL;
  972.          PPArg2 = NULL;
  973.  
  974.          FreeUMSConfig(SysUMSAccount, editor);
  975.  
  976.          error = SystemCall(outbuff);
  977.          }
  978.       else if (flags & (WF_NEW|WF_REPLY))
  979.          LineEditor(KMSTempDat);
  980.  
  981.       if (!error)
  982.          {
  983.          struct stat stat_buf;
  984.          error = stat(KMSTempDat, &stat_buf);
  985.  
  986.          FILE *msgdat;
  987.          if (error == 0 && (msgdat = fopen(KMSTempDat, "r")))
  988.             {
  989.             wmsgtext = (STRPTR)malloc((size_t)(stat_buf.st_size+1));
  990.             if (wmsgtext)
  991.                {
  992.                fread(wmsgtext, 1, stat_buf.st_size, msgdat);
  993.                wmsgtext[stat_buf.st_size] = '\0';
  994.                }
  995.             fclose(msgdat);
  996.             }
  997.  
  998.          /* Evt. ROT13 kodieren */
  999.  
  1000.          if (flags & WF_ROT13)
  1001.             Rot13(wmsgtext);
  1002.          }
  1003.       }
  1004.  
  1005.    /* Nachricht abspeichern */
  1006.  
  1007.    ULONG writetags[39];
  1008.    UBYTE t = 0;
  1009.  
  1010.    if (!error)
  1011.       {
  1012.       if ((!(current->AreaData.Type & ATYPE_PRIVATE) || !wtoaddr) && current->AreaData.WriteFlag & AWF_PSEUDO)
  1013.          writetags[t++] = UMSTAG_WFromName, writetags[t++] = KMS_LC->Session.CurrentUser->UserData.Name;
  1014.       if (wtoname)
  1015.          writetags[t++] = UMSTAG_WToName, writetags[t++] = wtoname;
  1016.       if (wtoaddr)
  1017.          writetags[t++] = UMSTAG_WToAddr, writetags[t++] = wtoaddr;
  1018.       writetags[t++] = UMSTAG_WCreationDate, writetags[t++] = wcreationdate;
  1019.       if (wsubject && strlen(wsubject))
  1020.          writetags[t++] = UMSTAG_WSubject, writetags[t++] = wsubject;
  1021.       if (flags & WF_REPLY)
  1022.          {
  1023.          if (RMsgID)
  1024.             writetags[t++] = UMSTAG_WReferID, writetags[t++] = RMsgID;
  1025.          writetags[t++] = UMSTAG_WChainUp, writetags[t++] = Lastmsg;
  1026.          }
  1027.       else if (flags & (WF_RESEND|WF_EDIT|WF_FORWARD))
  1028.          {
  1029.          if (RReferID)
  1030.             writetags[t++] = UMSTAG_WReferID, writetags[t++] = RReferID;
  1031.          if (RAttributes)
  1032.             {
  1033.             wattributes = strdup(RAttributes);
  1034.             writetags[t++] = UMSTAG_WAttributes, writetags[t++] = wattributes;
  1035.             }
  1036.          }
  1037.       if (!(flags & (WF_RESEND|WF_EDIT|WF_FORWARD)))
  1038.          {
  1039.          if (flags & WF_BINARY)
  1040.             {
  1041.             TEXT attrline[10+LEN_DOSFILE+1+10+LEN_NUMBER+1];
  1042.  
  1043.             writetags[t++] = UMSTAG_WAttributes;
  1044.             sprintf(attrline, "KMS_FNAME:%s KMS_FSIZE:%ld", BinaryName, BinarySize);
  1045.             wattributes = strdup(attrline);
  1046.             writetags[t++] = wattributes;
  1047.             }
  1048.          }
  1049.       sprintf(buff,"KMS.originstr%d", current->AreaData.OriginStr);
  1050.       if (myorg = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, buff, TAG_DONE))
  1051.          writetags[t++] = UMSTAG_WOrganization, writetags[t++] = myorg;
  1052.       if (strlen(wgroup))
  1053.          writetags[t++] = UMSTAG_WGroup, writetags[t++] = wgroup;
  1054.       if (KMSVers)
  1055.          writetags[t++] = UMSTAG_WNewsreader, writetags[t++] = KMSVers;
  1056.  
  1057.       writetags[t++] = UMSTAG_WMsgText, writetags[t++] = wmsgtext;
  1058.       writetags[t] = TAG_DONE;
  1059.       }
  1060.  
  1061.    BOOL sendit = FALSE;
  1062.    LONG res;
  1063.    UBYTE tag;
  1064.  
  1065.    if (!error && (KMS_LC->Session.CurrentUser->UserData.Flags & UF_EXTSEND))
  1066.       {
  1067.       while(!error && !sendit)
  1068.          {
  1069.          if (wattributes && strlen(wattributes))
  1070.             {
  1071.             PPArg = wattributes;
  1072.             SysMsg(CURR_MSG_ATTRIBS);
  1073.             PPArg = NULL;
  1074.             }
  1075.          if (wreplyname && strlen(wreplyname))
  1076.             {
  1077.             PPArg = wreplyname;
  1078.             PPArg2 = wreplyaddr;
  1079.             SysMsg(CURR_REPLY_TO);
  1080.             PPArg = NULL;
  1081.             PPArg2 = NULL;
  1082.             }
  1083.          if (wreplygroup && strlen(wreplygroup))
  1084.             {
  1085.             PPArg = wreplygroup;
  1086.             SysMsg(CURR_FOLLOWUP_TO);
  1087.             PPArg = NULL;
  1088.             }
  1089.  
  1090.          res = CmdInput(NULL, SEND_OPTS, "0123459", "9", 1, INF_PROMPT|INF_NUMERIC);
  1091.          if (Plop || ShutDown)
  1092.             error = 1;
  1093.          else if (res == 0) /* Abbruch */
  1094.             error = 1;
  1095.          else if (res == 9) /* Senden */
  1096.             sendit = TRUE;
  1097.          else if (res == 1) /* Reply-To */
  1098.             {
  1099.             if (wreplyname)
  1100.                {
  1101.                free(wreplyname);
  1102.                wreplyname = NULL;
  1103.                if (wreplyaddr)
  1104.                   free(wreplyaddr);
  1105.                wreplyaddr = NULL;
  1106.  
  1107.                tag = 0;
  1108.                while(writetags[tag] != UMSTAG_WReplyName && writetags[tag] != TAG_DONE)
  1109.                   tag++;
  1110.                if (writetags[tag] == UMSTAG_WReplyName)
  1111.                   writetags[tag++] = TAG_IGNORE, writetags[tag] = NULL;
  1112.  
  1113.                tag = 0;
  1114.                while(writetags[tag] != UMSTAG_WReplyAddr && writetags[tag] != TAG_DONE)
  1115.                   tag++;
  1116.                if (writetags[tag] == UMSTAG_WReplyAddr)
  1117.                   writetags[tag++] = TAG_IGNORE, writetags[tag] = NULL;
  1118.                }
  1119.             else
  1120.                {
  1121.                *buff = '\0';
  1122.                GetAlias(buff, GA_NAME, LEN_REALNAME);
  1123.  
  1124.                if (strlen(buff))
  1125.                   {
  1126.                   wreplyname = strdup(buff);
  1127.                   if (wreplyname)
  1128.                      {
  1129.                      tag = 0;
  1130.                      while(writetags[tag] != UMSTAG_WReplyName && writetags[tag] != TAG_IGNORE && writetags[tag] != TAG_DONE)
  1131.                         tag++;
  1132.                      if (writetags[tag] == TAG_DONE)
  1133.                         {
  1134.                         writetags[t++] = UMSTAG_WReplyName, writetags[t++] = wreplyname;
  1135.                         writetags[t] = TAG_DONE;
  1136.                         }
  1137.                      else
  1138.                         writetags[tag++] = UMSTAG_WReplyName, writetags[tag] = wreplyname;
  1139.                      
  1140.                      *buff = '\0';
  1141.                      GetAlias(buff, GA_ADDRESS, LEN_ADDRESS);
  1142.  
  1143.                      if (strlen(buff))
  1144.                         {
  1145.                         wreplyaddr = strdup(buff);
  1146.                         if (wreplyaddr)
  1147.                            {
  1148.                            tag = 0;
  1149.                            while(writetags[tag] != UMSTAG_WReplyAddr && writetags[tag] != TAG_IGNORE && writetags[tag] != TAG_DONE)
  1150.                               tag++;
  1151.                            if (writetags[tag] == TAG_DONE)
  1152.                               {
  1153.                               writetags[t++] = UMSTAG_WReplyAddr, writetags[t++] = wreplyaddr;
  1154.                               writetags[t] = TAG_DONE;
  1155.                               }
  1156.                            else
  1157.                               writetags[tag++] = UMSTAG_WReplyAddr, writetags[tag] = wreplyaddr;
  1158.                            }
  1159.                         }
  1160.                      }
  1161.                   }
  1162.                
  1163.                GetAlias(NULL, GA_RESET, 0);
  1164.                }
  1165.             }
  1166.          else if (res == 2) /* FollowUp-To */
  1167.             {
  1168.             if (wreplygroup)
  1169.                {
  1170.                free(wreplygroup);
  1171.                wreplygroup = NULL;
  1172.  
  1173.                tag = 0;
  1174.                while(writetags[tag] != UMSTAG_WReplyGroup && writetags[tag] != TAG_DONE)
  1175.                   tag++;
  1176.                if (writetags[tag] == UMSTAG_WReplyGroup)
  1177.                   writetags[tag++] = TAG_IGNORE, writetags[tag] = NULL;
  1178.                }
  1179.             else
  1180.                {
  1181.                struct AreaNode *anode;
  1182.  
  1183.                *PathString = '\0';
  1184.                strcpy(KMS_LC->Session.InputBuffer," ");
  1185.  
  1186.                while(strlen(KMS_LC->Session.InputBuffer) && stricmp(PathString, KMS_LC->Session.InputBuffer))
  1187.                   {
  1188.                   CmdInput(NULL, PROMPT_HKF_ADDPATH, NULL, PathString, LEN_KMSPATH, INF_PROMPT|INF_UPCASE|INF_DEFBUF);
  1189.                   if (Plop || ShutDown)
  1190.                      {
  1191.                      error = 1;
  1192.                      *KMS_LC->Session.InputBuffer = '\0';
  1193.                      }
  1194.  
  1195.                   if (strlen(KMS_LC->Session.InputBuffer))
  1196.                      {
  1197.                      if (anode = ChangeArea(KMS_LC->Session.InputBuffer))
  1198.                         {
  1199.                         if (anode->AreaData.ID != 1)
  1200.                            CreatePath(anode);
  1201.                         }
  1202.                      else
  1203.                         SysMsg(INVALID_PATH);
  1204.                      }
  1205.                   else
  1206.                      error = 1;
  1207.                   }
  1208.  
  1209.                if (!error)
  1210.                   {
  1211.                   wreplygroup = (STRPTR)malloc((size_t)(strlen(anode->AreaData.MBName)+1));
  1212.                   if (wreplygroup)
  1213.                      {
  1214.                      strcpy(wreplygroup, anode->AreaData.MBName);
  1215.                      tag = 0;
  1216.                      while(writetags[tag] != UMSTAG_WReplyGroup && writetags[tag] != TAG_IGNORE && writetags[tag] != TAG_DONE)
  1217.                         tag++;
  1218.                      if (writetags[tag] == TAG_DONE)
  1219.                         {
  1220.                         writetags[t++] = UMSTAG_WReplyGroup, writetags[t++] = wreplygroup;
  1221.                         writetags[t] = TAG_DONE;
  1222.                         }
  1223.                      else
  1224.                         writetags[tag++] = UMSTAG_WReplyGroup, writetags[tag] = wreplygroup;
  1225.                      }
  1226.                   }
  1227.                }
  1228.             }
  1229.          else if (res == 3 || res == 4 || res == 5) /* receipt-request / file-attach / Dringend */
  1230.             {
  1231.             STRPTR attribstring;
  1232.             STRPTR newwattrib, temp, arg;
  1233.             BOOL found = FALSE;
  1234.  
  1235.             if (res == 3)
  1236.                attribstring = "RECEIPT-REQUEST";
  1237.             else if (res == 4)
  1238.                attribstring = "FILE-ATTACH";
  1239.             else
  1240.                attribstring = "URGENT";
  1241.  
  1242.             if (wattributes)
  1243.                temp = strdup(wattributes);
  1244.             else
  1245.                temp = strdup("");
  1246.  
  1247.             if (temp)
  1248.                {
  1249.                newwattrib = (STRPTR)malloc(strlen(wattributes)+1);
  1250.  
  1251.                if (newwattrib)
  1252.                   {
  1253.                   *newwattrib = '\0';
  1254.  
  1255.                   for(arg = strtok(temp, " \t"); arg; arg = strtok(NULL, " \t"))
  1256.                      {
  1257.                      if (!stricmp(arg, attribstring))
  1258.                         found = TRUE;
  1259.                      else
  1260.                         {
  1261.                         if (strlen(newwattrib))
  1262.                            strcat(newwattrib, " ");
  1263.                         strcat(newwattrib, arg);
  1264.                         }
  1265.                      }
  1266.  
  1267.                   if (found)
  1268.                      {
  1269.                      free(wattributes);
  1270.                      wattributes = newwattrib;
  1271.                      }
  1272.                   else
  1273.                      {
  1274.                      FILE *fh = NULL;
  1275.                      BOOL doit;
  1276.                      TEXT dosbuff[LEN_DOSPATH+1];
  1277.  
  1278.                      free(newwattrib);
  1279.                      newwattrib = NULL;
  1280.  
  1281.                      if (res == 4) /* file-attach */
  1282.                         {
  1283.                         if (wsubject)
  1284.                            strcpy(KMS_LC->Session.InputBuffer, wsubject);
  1285.                         else
  1286.                            *KMS_LC->Session.InputBuffer = '\0';
  1287.  
  1288.                         do
  1289.                            {
  1290.                            if (KMS_LC->Device & DEV_CONSOLE)
  1291.                               {
  1292.                               strncpy(dosbuff, KMS_LC->Session.InputBuffer, LEN_DOSPATH);
  1293.                               dosbuff[LEN_DOSPATH] = '\0';
  1294.                               }
  1295.                            else if (!strchr(KMS_LC->Session.InputBuffer, ':') && !strchr(KMS_LC->Session.InputBuffer, '/'))
  1296.                               {
  1297.                               strcpy(dosbuff, KMSBase->UserDir);
  1298.                               strcat(dosbuff, KMS_LC->Session.CurrentUser->UserData.Name);
  1299.                               ConvertSpace(dosbuff);
  1300.                               strcat(dosbuff, "/");
  1301.                               strncat(dosbuff, KMS_LC->Session.InputBuffer, LEN_DOSFILE);
  1302.                               dosbuff[LEN_DOSPATH] = '\0';
  1303.                               }
  1304.                            else
  1305.                               *dosbuff = '\0';
  1306.  
  1307.                            if (*dosbuff && (fh = fopen(dosbuff, "r")))
  1308.                               {
  1309.                               fclose(fh);
  1310.                               doit = TRUE;
  1311.                               }
  1312.                            else
  1313.                               {
  1314.                               SysMsg(FILE_NOT_FOUND);
  1315.                               doit = FALSE;
  1316.                               }
  1317.  
  1318.                            if (!doit)
  1319.                               {
  1320.                               strcpy(dosbuff, KMS_LC->Session.InputBuffer);
  1321.  
  1322.                               if (KMS_LC->Device & DEV_CONSOLE)
  1323.                                  CmdInput(NULL, PROMPT_FILENAME, " ,%*?#~[]()!\"\\", dosbuff, LEN_DOSPATH, INF_PROMPT|INF_DEFBUF|INF_EXCLUDE);
  1324.                               else
  1325.                                  CmdInput(NULL, PROMPT_FILENAME, " /:,%*?#~[]()!\"\\", dosbuff, LEN_DOSFILE, INF_PROMPT|INF_DEFBUF|INF_EXCLUDE);
  1326.                               }
  1327.  
  1328.                            } while(!doit && *KMS_LC->Session.InputBuffer);
  1329.  
  1330.                         if (doit)
  1331.                            {
  1332.                            if (wsubject)
  1333.                               free(wsubject);
  1334.                            wsubject = strdup(dosbuff);
  1335.                            if (wsubject)
  1336.                               {
  1337.                               tag = 0;
  1338.                               while(writetags[tag] != UMSTAG_WSubject && writetags[tag] != TAG_DONE)
  1339.                                  tag++;
  1340.                               if (writetags[tag] == TAG_DONE)
  1341.                                  {
  1342.                                  writetags[t++] = UMSTAG_WSubject, writetags[t++] = wsubject;
  1343.                                  writetags[t] = TAG_DONE;
  1344.                                  }
  1345.                               else
  1346.                                  writetags[++tag] = wsubject;
  1347.  
  1348.                               doit = TRUE;
  1349.                               }
  1350.                            else
  1351.                               doit = FALSE;
  1352.                            }
  1353.                         }
  1354.  
  1355.                      if (doit)
  1356.                         {
  1357.                         newwattrib = (STRPTR)malloc(strlen(wattributes)+1+strlen(attribstring)+1);
  1358.                         if (newwattrib)
  1359.                            {
  1360.                            strcpy(newwattrib, wattributes);
  1361.                            if (strlen(newwattrib))
  1362.                               strcat(newwattrib, " ");
  1363.                            strcat(newwattrib, attribstring);
  1364.                            }
  1365.                         free(wattributes);
  1366.                         wattributes = newwattrib;
  1367.                         }
  1368.                      }
  1369.                   }
  1370.  
  1371.                free(temp);
  1372.                }
  1373.  
  1374.             if (!wattributes || !strlen(wattributes))
  1375.                {
  1376.                tag = 0;
  1377.                while(writetags[tag] != UMSTAG_WAttributes && writetags[tag] != TAG_DONE)
  1378.                   tag++;
  1379.                if (writetags[tag] == UMSTAG_WAttributes)
  1380.                   writetags[tag] = TAG_IGNORE, writetags[tag+1] = NULL;
  1381.                if (wattributes)
  1382.                   free(wattributes);
  1383.                wattributes = NULL;
  1384.                }
  1385.             else
  1386.                {
  1387.                tag = 0;
  1388.                while(writetags[tag] != UMSTAG_WAttributes && writetags[tag] != TAG_IGNORE && writetags[tag] != TAG_DONE)
  1389.                   tag++;
  1390.                if (writetags[tag] == TAG_DONE)
  1391.                   {
  1392.                   writetags[t++] = UMSTAG_WAttributes, writetags[t++] = wattributes;
  1393.                   writetags[t] = TAG_DONE;
  1394.                   }
  1395.                else
  1396.                   writetags[tag++] = UMSTAG_WAttributes, writetags[tag] = wattributes;
  1397.                }
  1398.             }
  1399.          }
  1400.       }
  1401.    else if (!error)
  1402.       sendit = YNRequest(SEND_REALLY, TRUE);
  1403.  
  1404.    if (!sendit)
  1405.       error = 1;
  1406.  
  1407.    while(!error && sendit)
  1408.       {
  1409.       sendit = FALSE;
  1410.  
  1411.       UMSMsgNum written;
  1412.       if (written = WriteUMSMsg(MyUMSAccount, (struct TagItem *)&writetags[0]))
  1413.          {
  1414.          sprintf(buff, "%ld", written);
  1415.          PPArg = buff;
  1416.          SysMsg(MSG_WRITTEN);
  1417.          PPArg = NULL;
  1418.  
  1419.          /* Local-Flags 0 (sichtb.) und 2 (in Gruppe) setzen */
  1420.  
  1421.          UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg,        written,
  1422.                                      UMSTAG_SelWriteLocal, TRUE,
  1423.                                      UMSTAG_SelSet,        KMSLSTATF_Visible|KMSLSTATF_InGroup,
  1424.                                      TAG_DONE);
  1425.  
  1426.          sendRexxCmd("CHECKMAIL", NULL, NULL, NULL, NULL, "KMS");
  1427.          }
  1428.       else if (UMSErrNum(MyUMSAccount) == UMSERR_NoReader)
  1429.          {
  1430.          PPArg = wtoname;
  1431.          PPArg2 = wtoaddr;
  1432.          SysMsg(INVALID_ADDRESS);
  1433.          PPArg = NULL;
  1434.          PPArg2 = NULL;
  1435.  
  1436.          if (YNRequest(SEND_RETRY, TRUE))
  1437.             {
  1438.             *buff = '\0';
  1439.             GetAlias(buff, GA_NAME, LEN_REALNAME);
  1440.             if (strlen(buff))
  1441.                {
  1442.                if (wtoname)
  1443.                   free(wtoname);
  1444.                wtoname = strdup(buff);
  1445.                if (wtoname)
  1446.                   {
  1447.                   tag = 0;
  1448.                   while(writetags[tag] != UMSTAG_WToName && writetags[tag] != TAG_DONE)
  1449.                      tag++;
  1450.                   if (writetags[tag] == TAG_DONE)
  1451.                      {
  1452.                      writetags[t++] = UMSTAG_WToName, writetags[t++] = wtoname;
  1453.                      writetags[t] = TAG_DONE;
  1454.                      }
  1455.                   else
  1456.                      writetags[++tag] = wtoname;
  1457.  
  1458.                   if (flags & WF_BINARY)
  1459.                      sendit = TRUE;
  1460.                   else
  1461.                      {
  1462.                      *buff = '\0';
  1463.                      GetAlias(buff, GA_ADDRESS, LEN_ADDRESS);
  1464.                      tag = 0;
  1465.                      while(writetags[tag] != UMSTAG_WToAddr && writetags[tag] != TAG_IGNORE && writetags[tag] != TAG_DONE)
  1466.                         tag++;
  1467.                      if (strlen(buff))
  1468.                         {
  1469.                         if (wtoaddr)
  1470.                            free(wtoaddr);
  1471.                         wtoaddr = strdup(buff);
  1472.                         if (wtoaddr)
  1473.                            {
  1474.                            if (writetags[tag] == TAG_DONE)
  1475.                               {
  1476.                               writetags[t++] = UMSTAG_WToAddr, writetags[t++] = wtoaddr;
  1477.                               writetags[t] = TAG_DONE;
  1478.                               }
  1479.                            else
  1480.                               writetags[tag++] = UMSTAG_WToAddr, writetags[tag] = wtoaddr;
  1481.  
  1482.                            sendit = TRUE;
  1483.                            }
  1484.                         }
  1485.                      else
  1486.                         {
  1487.                         if (wtoaddr)
  1488.                            {
  1489.                            free(wtoaddr);
  1490.                            wtoaddr = NULL;
  1491.                            }
  1492.  
  1493.                         if (writetags[tag] == UMSTAG_WToAddr)
  1494.                            {
  1495.                            writetags[tag++] = TAG_IGNORE;
  1496.                            writetags[tag] = NULL;
  1497.                            }
  1498.  
  1499.                         sendit = TRUE;
  1500.                         }
  1501.                      }
  1502.                   }
  1503.                }
  1504.  
  1505.             GetAlias(NULL, GA_RESET, 0);
  1506.             }
  1507.          else
  1508.             error = 1;
  1509.          }
  1510.       else
  1511.          SystemError("WriteMsg", "WriteUMSMsg");
  1512.       }
  1513.  
  1514.    /* Speicher wieder freigeben */
  1515.  
  1516.    if (flags & (WF_REPLY|WF_RESEND|WF_EDIT|WF_FORWARD))
  1517.       FreeUMSMsg(MyUMSAccount, Lastmsg);
  1518.  
  1519.    if (myorg)
  1520.       FreeUMSConfig(SysUMSAccount, myorg);
  1521.  
  1522.    if (wmsgtext && strlen(wmsgtext))
  1523.       free(wmsgtext);
  1524.    if (wreplyname)
  1525.       free(wreplyname);
  1526.    if (wreplyaddr)
  1527.       free(wreplyaddr);
  1528.    if (wreplygroup)
  1529.       free(wreplygroup);
  1530.    if (wattributes)
  1531.       free(wattributes);
  1532.    if (!(flags & (WF_RESEND|WF_EDIT)))
  1533.       {
  1534.       if (wsubject && strlen(wsubject))
  1535.          free(wsubject);
  1536.       }
  1537.    if (wtoname)
  1538.       free(wtoname);
  1539.    if (wtoaddr)
  1540.       free(wtoaddr);
  1541.  
  1542.    if (error)
  1543.       return FALSE;
  1544.    else
  1545.       return TRUE;
  1546.    }
  1547.  
  1548. ///
  1549.